package org.amphiprion.descentv2assistant.adapter;

import java.util.LinkedHashMap;

import org.amphiprion.descentv2assistant.R;
import org.amphiprion.descentv2assistant.ui.fragment.HeroListFragment;
import org.amphiprion.descentv2assistant.ui.fragment.LieutenantListFragment;
import org.amphiprion.descentv2assistant.ui.fragment.MonsterListFragment;
import org.amphiprion.descentv2assistant.ui.views.TitleProvider;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

public class MainViewPagerAdapter extends FragmentPagerAdapter implements TitleProvider {
	private final LinkedHashMap<String, Fragment> mScreens;

	public MainViewPagerAdapter(FragmentActivity activity, FragmentManager fm) {
		super(fm);
		this.mScreens = new LinkedHashMap<String, Fragment>();
		// if (App.isPhone(activity)) {
		// this.mScreens.put(activity.getString(R.string.title_tab_discovery), DiscoveryFragment.newInstance());
		// }
		this.mScreens.put(activity.getString(R.string.title_tab_all_heroes), HeroListFragment.newInstance());
		this.mScreens.put(activity.getString(R.string.title_tab_all_monsters), MonsterListFragment.newInstance());
		this.mScreens.put(activity.getString(R.string.title_tab_all_lieutenants), LieutenantListFragment.newInstance());
		// this.mScreens.put(activity.getString(R.string.title_tab_recent), RecentEpisodeListFragment.newInstance());

	}

	@Override
	public Fragment getItem(int paramInt) {
		return this.mScreens.values().toArray(new Fragment[this.mScreens.size()])[paramInt];
	}

	@Override
	public String getTitle(int paramInt) {
		return this.mScreens.keySet().toArray(new String[this.mScreens.size()])[paramInt];
	}

	@Override
	public int getCount() {
		return this.mScreens.size();
	}

	public void doFilter(int currentItem) {
		Fragment f = getItem(currentItem);
		if (f instanceof MonsterListFragment) {
			((MonsterListFragment) f).doFilter();
		} else if (f instanceof HeroListFragment) {
			((HeroListFragment) f).doFilter();
		} else if (f instanceof LieutenantListFragment) {
			((LieutenantListFragment) f).doFilter();
		}

	}

}
